define(function(require, exports, module){
	var mycollectTemp = require("text!../template/mycollects.html");

	module.exports = Nuui.View.extend({

		template:mycollectTemp,

		onRender:function(){
			var view = this;
			view.$('.smart-title a').on('tap', function(){
				var self = $(this);
				self.addClass('at-active').siblings().removeClass('at-active');
				return false;
			});

			var queryCollectList=function(){
				App.request(App.server.getServePath(App.path.collectAllAction), {
				//data:"",
				success:function(data){
					if(data.ec){
                        alert(data.em);
					}else {
                        var groupList = data.collectList.GovernmentAdviser.list;
                        var groupList1 = data.collectList.IndustryExperts.list;

                        var arr = [];
                        //分类创建数组；标题首字母缩写
						var zftt=[];
						var rdhd=[];
						var rzqy=[];
						var hyzj=[];
						var fwxm=[];
						var zbxm=[];
						var zfld=[];
                        var tpl= '';
                        for(var i = 0; i < groupList.length; i++){
                        	arr.push(groupList[i].classify);
                            tpl += '<div class="all" data-code="'+groupList[i].code+'" data-productCode="'+groupList[i].productCode+'" >\n' +
                                '\t\t\t\t<ul>\n' +
                                '\t\t\t\t\t<li class="collect_list">\n' +
                                '\t\t\t\t\t\t<div class="img_left">\n' +
                                '\t\t\t\t\t\t\t<img src="../../../images/collect/'+groupList[i].avatar+'" alt="">\n' +
                                '\t\t\t\t\t\t</div>\n' +
                                '\t\t\t\t\t\t<div class="poll_right">\n' +
                                '\t\t\t\t\t\t\t<h3>'+groupList[i].name+'</h3>\n' +
                                '\t\t\t\t\t\t\t<p><span>'+groupList[i].data+'</span><span>'+groupList[i].time+'</span><img class="cancel_btn" src="../../../images/collect/'+groupList[i].collectIcon+'" alt=""></p>\n' +
                                '\t\t\t\t\t\t</div>\n' +
                                '\t\t\t\t\t</li>\n' +
                                '\t\t\t\t</ul>\n' +
                                '\t\t\t</div>';
                        }
                        for(var j=0;j<arr.length;j++){
                        	if(arr[j]=="政府头条"){
                                zftt.push(arr[j])
							}else if(arr[j]=="热点活动"){
                        		rdhd.push(arr[j])
							}else if(arr[j]=="认证企业"){
                                rzqy.push(arr[j])
                            }else if(arr[j]=="行业专家"){
                                hyzj.push(arr[j])
                            }else if(arr[j]=="服务项目"){
                                fwxm.push(arr[j]);
                            }else if(arr[j]=="招标项目"){
                                zbxm.push(arr[j])
                            }else {
                                zfld.push(arr[j])
							}
						}
						var arr1=[zftt.length,rdhd.length,rzqy.length,hyzj.length,fwxm.length,zbxm.length,zfld.length];
                        var tpl1='';
                        for(var i = 0; i < groupList1.length; i++) {
							tpl1 += '<div class="category">\n' +
								'\t\t\t\t<ul>\n' +
								'\t\t\t\t\t<li class="collect_list">\n' +
								'\t\t\t\t\t\t<div class="img_left">\n' +
								'\t\t\t\t\t\t\t<img src="../../../images/collect/'+groupList1[i].avatar+'" alt="">\n' +
								'\t\t\t\t\t\t</div>\n' +
								'\t\t\t\t\t\t<div class="poll_right">\n' +
								'\t\t\t\t\t\t\t<h3 data-title="'+groupList1[i].name+'">'+groupList1[i].name+'</h3>\n' +
								'\t\t\t\t\t\t\t<p data-number="'+arr1[i]+'">共<span>'+arr1[i]+'</span>个</p>\n' +
								'\t\t\t\t\t\t</div>\n' +
								'\t\t\t\t\t</li>\n' +
								'\t\t\t\t</ul>\n' +
								'\t\t\t</div>';


                        }
                        view.$("#myCollect").html(tpl);
                        view.$('.smart-left').on('tap', function(){
                            view.$("#myCollect").html(tpl);
                            return false;
                        });
                        view.$('.smart-right').on('tap', function(){
                            view.$("#myCollect").html(tpl1);
                            return false;
                        });
                    }
					}
				});
			};
            queryCollectList();

            /*路由跳转事件委托*/
            view.$('#myCollect').on('tap','.category',function(){
				var targetCode=$(this).attr('data-code');
				var targetId=$(this).attr('data-id');
				/*分类存储参数 标题和类个数*/
				var title = $(this).find("h3").attr('data-title');
				var number = $(this).find("p").attr('data-number');
				App.storage.set('smartGroupMenuCode',targetCode);
				App.storage.set('smartGroupListId',targetId);
				App.storage.set('title',title);
				App.storage.set('number',number);
				App.navigate("example/index/mycollectdetail", true);
				return false;
            })
		},

		onShow:function(){
			var view=this;
			view.$('.smart-content').on('tap','.all .cancel_btn',function(e){
				e.stopPropagation();
				e.cancelBubble=true;
				var target=$(this).closest('.all');
				$(target).addClass('active').delay(300).queue(function(){
					$(this).remove();
					$(this).dequeue();
				})
			})
			view.$('#myCollect').on('tap','.all',function(){
				 App.storage.set('productCode',$(this).attr('data-productCode'));
				 App.storage.set('yunCode',$(this).attr('data-code'));
				 App.navigate("example/index/MDM",true);
				 return false;
			 })
		}
	});
});
